package com.miao.common.entity;

/**
 * @author MiaoWenqing
 * @description 用于返回结果的封装
 * @date 2021/1/16 16:02
 * code ：
 *   2000 成功
 *   4000 失败
 */
public class R{


    private int code;//状态码
    private  String msg;//消息
    private Object data; //数据

    public R(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public R() {
    }

    @Override
    public String toString() {
        return "R{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public static R ok(){
        R r = new R();
        r.code=2000;
        r.data=null;
        r.msg="成功";
        return r;
    }
    public static R ok(Object data){
        R r = new R();
        r.code=2000;
        r.data=data;
        r.msg="成功";
        return r;
    }

    public static R error(){
        R r = new R();
        r.code=4000;
        r.data=null;
        r.msg="失败";
        return r;
    }
    public static R error( Object data){
        R r = new R();
        r.code=4000;
        r.data=data;
        r.msg="失败";
        return r;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
